package com.example.chinalin.viewpagerdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.nineoldandroids.view.ViewHelper;

public class ScrollViewActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scroll_view);

//        View container = LayoutInflater.from(this).inflate(R.layout.activity_scroll_view,null);
//        RelativeLayout relativeLayout = (RelativeLayout) container.findViewById(R.id.ltdrelativeLayout);
//        ImageView imageView = new ImageView(this) ;
//        imageView.setImageResource(R.drawable.image_1);
        RelativeLayout relativeLayout = (RelativeLayout)super.findViewById(R.id.ltdrelativeLayout) ;
//        ImageView imageView = new ImageView(this);
//        imageView.setImageResource(R.drawable.image_1);
////        imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
////        imageView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT));
////        imageViews[i] = imageView;
//        RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(100,100);
//        lp.setMargins(0,0, 0, 0);
//        imageView.setLayoutParams(lp);
//        relativeLayout.addView(imageView);

//                int left = 100;
        for (int i=0; i<10 ; i++){
            for (int j=0;j<10 ;j++){
                ImageView imageView = new ImageView(this) ;
                imageView.setFocusable(true);
                Glide
                        .with(ScrollViewActivity.this)
                        .load(constant.eatFoodyImages[(i+j)%14])
                        .into(imageView);
                /*imageView.setImageResource(R.drawable.image_1);*/
                RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(300,300);
                lp.setMargins(i*300,j*300, 0, 0);
                imageView.setLayoutParams(lp);
                //            imageView.setLayoutParams(layoutParams);
                imageView.requestLayout();
                imageView.setId(i*10+j);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(ScrollViewActivity.this,"id:"+v.getId(),Toast.LENGTH_SHORT).show();
                    }
                });
                imageView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus){
                            ImageView iv = (ImageView)v;
                            iv.setScaleType(ImageView.ScaleType.FIT_XY);
                            ViewHelper.setScaleX(v, 1.1f);
                            ViewHelper.setScaleY(v, 1.1f);
                        }else{
                            ImageView iv = (ImageView)v;
                            iv.setScaleType(ImageView.ScaleType.CENTER);
//                            ViewHelper.setScaleX(v, 1.0f);
//                            ViewHelper.setScaleY(v, 1.0f);
                        }
                    }
                });
                relativeLayout.addView(imageView);
            }
        }

    }
}
